module neo.tetris.view {
	/**
	 *
	 * @author 
	 *
	 */
	export class LoginView extends eui.Component {
        public loginBtn: eui.Button;
    	
        public nameLabel: eui.Label;
        
        public headIcon: eui.Image;
        
		public constructor() {
            super();
            
            this.addEventListener(eui.UIEvent.COMPLETE,this.handleEvent,this);
            this.addEventListener(egret.Event.ADDED_TO_STAGE,this.handleEvent,this);
            this.addEventListener(egret.Event.REMOVED_FROM_STAGE,this.handleEvent,this);
            this.skinName = "resource/custom_skins/LoginViewSkin.exml";
        }

        private handleEvent(evt: egret.Event): void {
            switch(evt.type) {
                case egret.Event.ADDED_TO_STAGE:
                    break;
                case egret.Event.REMOVED_FROM_STAGE:
                    break;
                case eui.UIEvent.COMPLETE:
                    this.nameLabel.strokeColor = 0x333333;
                    this.nameLabel.stroke = 3;
                    this.nameLabel.text = "Guest" + Math.floor(Math.random() * 100);
                    this.headIcon.source = "http://192.168.31.188:3001/resource/arts/" + (53 + Math.floor(Math.random() * 10)) + ".gif";
                    this.loginBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.handleTouchEvent,this);
                    break;
            }
        }

        private handleTouchEvent(evt:egret.TouchEvent):void {
            Main.instance.userService.login(this.nameLabel.text, String(this.headIcon.source));
            Main.instance.battleService.matchAuto();
        }
	}
}
